<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 *
 * @author Joker
 *        
 */
class CompanyType extends Model
{
    
    protected $table='company_type';
    
    protected $primaryKey = 'id';
    
    protected $fillable = ['id','name','parent_id','sort','identify','description'];

    /**
     * 根据子分类获取父分类
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function parentCate()
    {
        return $this->belongsTo('App\Models\CompanyType', 'parent_id', 'id');
    }

    /**
     * 获取某个父分类下的所有子分类
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function childrenCates()
    {
        return $this->hasMany('App\Models\CompanyType', 'parent_id', 'id');
    }
    
}